﻿// CMesDlg.cpp: 实现文件
//

#include "pch.h"
#include "afxdialogex.h"
#include "CMesDlg.h"
#include "resource.h"
#include "ProjectAA.h"

// CMesDlg 对话框

IMPLEMENT_DYNAMIC(CMesDlg, CDialogEx)

CMesDlg::CMesDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_MES, pParent)
{

}

CMesDlg::~CMesDlg()
{
}

void CMesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CMesDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON_SAVE, &CMesDlg::OnBnClickedButtonSave)
	ON_BN_CLICKED(IDC_BUTTON_CHECK_GD, &CMesDlg::OnBnClickedButtonCheckGd)
END_MESSAGE_MAP()


// CMesDlg 消息处理程序

BOOL CMesDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	((CButton*)GetDlgItem(IDC_CHECK_ISOPENMES))->SetCheck(gSystemMgr.MesFlag);
	SetDlgItemText(IDC_EDIT_MES_IP, gSystemMgr.m_cstrIPMes);
	SetDlgItemInt(IDC_EDIT_MES_PORT, gSystemMgr.m_nPortMes);
	SetDlgItemText(IDC_EDIT_ST10_GX, gSystemMgr.st10wp_code);
	SetDlgItemText(IDC_EDIT_MES_GD, gSystemMgr.gdNo);


	CWnd* ctrl = GetTopWindow();
	while (ctrl != NULL)
	{
		ctrl->EnableWindow(gSystemMgr.isAdmin ? TRUE : FALSE);
		ctrl = ctrl->GetNextWindow();
	}
	if (!gSystemMgr.isAdmin)
	{
		GetDlgItem(IDC_EDIT_MES_GD)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(TRUE);
		GetDlgItem(IDC_BUTTON_CHECK_GD)->EnableWindow(TRUE);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CMesDlg::OnBnClickedButtonSave()
{
	gSystemMgr.MesFlag = ((CButton*)GetDlgItem(IDC_CHECK_ISOPENMES))->GetCheck();
	GetDlgItemText(IDC_EDIT_MES_IP, gSystemMgr.m_cstrIPMes);
	gSystemMgr.m_nPortMes = GetDlgItemInt(IDC_EDIT_MES_PORT);
	GetDlgItemText(IDC_EDIT_ST10_GX, gSystemMgr.st10wp_code);
	GetDlgItemText(IDC_EDIT_MES_GD, gSystemMgr.gdNo);

	CString cstr = L"";
	cstr.Format(L"%d", gSystemMgr.MesFlag);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"MesFlag", cstr);
	cstr.Format(L"%d", gSystemMgr.m_nPortMes);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"m_nPortMes", cstr);

	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"m_cstrIPMes", gSystemMgr.m_cstrIPMes);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"st10wp_code", gSystemMgr.st10wp_code);
	gSystemMgr.m_cMesConfigIni.SaveConfigIni(L"MES", L"gdNo", gSystemMgr.gdNo);
}

void CMesDlg::OnBnClickedButtonCheckGd()
{
	CString gd = L"";
	GetDlgItemText(IDC_EDIT_MES_GD, gd);
	USES_CONVERSION;
	bool v = gSystemMgr.MesCheckGD(T2A(gd));
	if (v)
	{
		MessageBox(L"工单OK", L"校验工单");
	}
	else
	{
		MessageBox(L"工单NG", L"校验工单", MB_ICONERROR);
	}
}
